package kr.co.redbean.frame
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import kr.co.redbean.events.MenuEvent;
	import kr.co.redbean.controls.MemberButton;

	public final class MemberMenu extends MainFrame implements IMainFrame
	{
		private var _login:MemberButton;
		private var _join:MemberButton;
		private var _logout:MemberButton;
		private var _my:MemberButton;
		private var _wishes:MemberButton;
		private var _orders:MemberButton;
		private var _sep1:Sprite;
		private var _sep2:Sprite;
		private var _sep3:Sprite;
		
		
		public function MemberMenu()
		{
			super();
			
			// start app
			// if logged in
			loggedIn();
			
			addEventListener(Event.ADDED_TO_STAGE, setPlacement);
		}
		
		public function setPlacement($e:Event=null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, setPlacement);
			
			x = posF.left;
			y = posF.top - MENUBAR_HEIGHT + 3;
			
			// if logged in
			_login.x = 0;
			_join.x = _login.width + 20;
			setSeperator(_sep1, _login, _join);
			
			// if logged out
//			_logout.x = 0;
//			_my.x = _logout.width + 15;
//			_wishes.x = _my.x + _my.width + 15;
//			_orders.x = _wishes.x + _wishes.width + 15;
//			setSeperator(_sep1, _logout, _my);
//			setSeperator(_sep2, _my, _wishes);
//			setSeperator(_sep3, _wishes, _orders);
			
			// seperator
			
		}
		private function loggedIn():void {
			_login = new MemberButton('LOGIN');
			_join = new MemberButton('JOIN');
			_sep1 = new Sprite;
			_sep1.mouseEnabled = false;
			
			addChild(_login);
			addChild(_join);
			addChild(_sep1);
		}
		private function loggedOut():void {
			_logout = new MemberButton('LOGOUT');
			_my = new MemberButton('MY');
			_wishes = new MemberButton('WISHES');
			_orders = new MemberButton('ORDERS');
			_sep1 = new Sprite;
			_sep1.mouseEnabled = false;
			_sep2 = new Sprite;
			_sep2.mouseEnabled = false;
			_sep3 = new Sprite;
			_sep3.mouseEnabled = false;
			
			addChild(_logout);
			addChild(_my);
			addChild(_wishes);
			addChild(_orders);
			addChild(_sep1);
			addChild(_sep2);
			addChild(_sep3);
		}
		private function setSeperator(seperator:Sprite, a:MemberButton, b:MemberButton):void {
			seperator.graphics.clear();
			seperator.graphics.lineStyle(1,0xCCCCCC);
			seperator.graphics.moveTo((a.x + a.width) + ((b.x - (a.x + a.width))/2 + 1), a.y + 4);
			seperator.graphics.lineTo((a.x + a.width) + ((b.x - (a.x + a.width))/2 + 1), a.height - 3);
		}
		
		override public function set alpha(value:Number):void {
			super.alpha = value;
		}
	}
}